<?
class Vector{
	private $elements = Array();

	public function Vector(){
		$this->elements = Array();
	}

	public function add($elem){
		$this->elements[] = $elem;
	}

	public function get($index){
		return $this->elements[$index];
	}

	public function remove($elem){
		for($i = 0; $i < sizeof($this->elements); $i++){
			if($this->elements[$i] == $elem){
				$this->removeElementAt($i);
				return;
			}
		}
	}

	public function removeElementAt($index){
		for($i = 0; $i < sizeof($this->elements); $i++){
			if($i > $index){
				$this->elements[$i-1] = $this->elements[$i];
			}
		}
		unset($this->elements[$this->size()-1]);
	}

	public function toString() {
		$res = "";
		for($i = 0; $i < sizeof($this->elements); $i++){
			if($i > 0) $res .= ".";
			if(get_class($this->elements[$i]) == null){
				if($this->elements[$i] != ""){
					$res .= $this->get($i);
				}
			} else {
				$res .= $this->get($i)->getId();
			}
 		}
		return $res;
	}

	public function fromString($value, $class = false){
		$list = explode(".", $value);

		$this->elements = Array();
		if(count($list) == 1 && $list[0] == ""){
			return;
		}
		if($class){
			for($i = 0; $i < sizeof($list);$i++){
				$obj = new $class();
				$obj->get($list[$i]);
				$this->add($obj);
			}
		} else {
			$this->elements = $list;
		}
	}

	public function size(){
		return sizeof($this->elements);
	}
}
?>